package com.sca.api.system.domain;

import com.alibaba.druid.filter.config.ConfigTools;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.sca.core.common.annotation.Excel;
import com.sca.core.common.annotation.Excel.ColumnType;
import com.sca.core.common.web.BaseEntity;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 系统访问记录表 sys_logininfor
 * 
 * @author ruoyi
 */
public class SysLogininfor extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** ID */
    @Excel(name = "序号", cellType = ColumnType.NUMERIC)
    private Long infoId;

    /** 用户账号 */
    @Excel(name = "用户账号")
    private String userName;

    /** 状态 0成功 1失败 */
    @Excel(name = "状态", readConverterExp = "0=成功,1=失败")
    private String status;

    /** 地址 */
    @Excel(name = "地址")
    private String ipaddr;

    /** 描述 */
    @Excel(name = "描述")
    private String msg;

    /** 访问时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "访问时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date accessTime;

    public Long getInfoId()
    {
        return infoId;
    }

    public void setInfoId(Long infoId)
    {
        this.infoId = infoId;
    }

    public String getUserName()
    {
        return userName;
    }

    public void setUserName(String userName)
    {
        this.userName = userName;
    }

    public String getStatus()
    {
        return status;
    }

    public void setStatus(String status)
    {
        this.status = status;
    }

    public String getIpaddr()
    {
        return ipaddr;
    }

    public void setIpaddr(String ipaddr)
    {
        this.ipaddr = ipaddr;
    }

    public String getMsg()
    {
        return msg;
    }

    public void setMsg(String msg)
    {
        this.msg = msg;
    }

    public Date getAccessTime()
    {
        return accessTime;
    }

    public void setAccessTime(Date accessTime)
    {
        this.accessTime = accessTime;
    }

    public static void main(String[] args)throws Exception {
        String password = ConfigTools.encrypt("");



        System.out.println(password);

        String decrypt = ConfigTools.decrypt(password);
        System.out.println(decrypt);

        System.out.println("---------------");
        String[] strs=new String[]{};

        test1(strs);

//        String decrypt = ConfigTools.decrypt(null);
//        System.out.println(decrypt);
        int byteread=0;
//        System.out.println(byteread);
//

       // File file =new File("/wuyang/sftp/20210edee63551e9.xlsx");
       // System.out.println(validateFileName(file));
        File file =new File("/home/zcils/tools-service/bin/mapfiles/20210edee63551e9.xlsx");
//        File file =new File("f:/wuyang/sftp/20210edee63551e9.xlsx");
        System.out.println(validateFileName(file));
        String  pathUsingCanonical=file.getCanonicalPath();
        String  pathUsingAbsolute = file.getAbsolutePath();
        String absolutePath = file.getAbsolutePath();
        System.out.println(pathUsingCanonical);
        System.out.println(pathUsingAbsolute);
        System.out.println(absolutePath);
        if(file.exists()){
            System.out.println("存在");
        }else{
            System.out.println("bu存在");
        }
//
//        File file = new File("/Users/martin6699/test.txt");
//        printPaths(file);
//
//        // relative path
//        file = new File("test.xsd");
//        printPaths(file);
//        // complex relative paths
//        file = new File("/Users/martin6699/../martin6699/test.txt");
//        printPaths(file);
//        // URI paths
//        file = new File(new URI("file:///Users/martin6699/test.txt"));
//        printPaths(file);
//
//        // symbolic links  软链接 /Users/martin6699/logs ---> /tmp/Data/logs
//        file = new File("/Users/martin6699/logs/test.txt");
//        printPaths(file);

    }

    private static Pattern FilePattern=Pattern.compile("[\\\\/:*\''<>|]");
    public  static boolean  validateFileName(File file) throws IOException, SecurityException{
        String goodPattern = "[\\s\\\\/:\\*\\?\\\''<>|]";
        goodPattern="[\\\\/:*\''<>|]";
        ///home/zcils/tools-service/bin/mapfiles/dd.text
        goodPattern="home/zcils/tools-service/bin/mapfiles/(\\w|\\s|\\.|-){1,100}";
        Pattern p = Pattern.compile(goodPattern, Pattern.CASE_INSENSITIVE);
        String  pathUsingCanonical=file.getCanonicalPath();
        String  pathUsingAbsolute = file.getAbsolutePath();
        System.out.println(pathUsingCanonical);
        System.out.println(pathUsingAbsolute);
        Matcher m = p.matcher(file.getCanonicalPath());
        if(!m.matches())
        {
            return false;
        }
        return true;
    }


    private static String filenameFilter(String str) throws IOException {
        return str==null?null:FilePattern.matcher(str).replaceAll("");
    }


    private static void printPaths(File file) throws IOException {
        System.out.println("Absolute Path: " + file.getAbsolutePath());
        System.out.println("Canonical Path: " + file.getCanonicalPath());
        System.out.println("Path: " + file.getPath());
        System.out.println("----------------------------------------------------------------");
    }

    private static void test1(String[] str) throws IOException {
        for(String d:str){
            System.out.println(d);
        }
        System.out.println("数据结束");
    }
}